package com.zynn.service.module.es.controller;

import com.zynn.common.core.base.BaseController;
import com.zynn.common.pojo.dto.zuul.LogInfoDTO;
import com.zynn.common.pojo.result.Result;
import com.zynn.common.pojo.result.ResultUtil;
import com.zynn.service.module.es.service.SyncLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 记录日志
 * @author 刘天元
 */
@Slf4j
@RestController
@Validated
@RequestMapping("sync/log")
public class SyncLogController extends BaseController {

    @Autowired
    private SyncLogService syncLogService;


    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result syncLog(@RequestBody LogInfoDTO logInfoDTO) {
        syncLogService.syncOneLog(logInfoDTO);
        return ResultUtil.success();
    }

    @GetMapping(value = "/countErrorAPI")
    public Result countErrorAPI(int minute) {
        Integer count = syncLogService.countErrorAPI(minute);
        return ResultUtil.success(count);
    }
}
